
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module http.session
* @author: Hjava
* @description: HTTP模块中的协议
* @since: 2018-07-22 15:56:18
*/
var http_constant_1 = __webpack_require__(/*! _http/http.constant */ "./src/core/http/http.constant.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var bufferType_1 = __webpack_require__(/*! _util/bufferType */ "./src/core/utils/bufferType.ts");
var base64_1 = __webpack_require__(/*! _util/base64 */ "./src/core/utils/base64.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var httpSession = {};
/**
 * 服务器端历史消息
 * @type {Function}
 */
httpSession.MsgHistoryRes = protocol_1.default.Response.extend({
    uri: http_constant_1.default.HTTP.URI_MSG_HISTORY_RES,
    init: function () {
        this.uid = 0;
        this.msgs = [];
        this.next = 0;
        this.rescode = 0;
        this.requestId = 0;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.msgs, bufferType_1.default.ARRAY_ARRAY);
        this.push(this.next);
        this.push(this.rescode);
        this.push(this.requestId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        var byteItems = this._popArrayArray();
        for (var i = 0; i < byteItems.length; i++) {
            if (byteItems[i].byteLength > 0) {
                this.msgs.push(protocol_1.default.Response.fromBuffer(byteItems[i]));
            }
        }
        this.next = this.popInt();
        this.rescode = this.popInt();
        this.requestId = this.popLong().value();
    }
});
/**
 * 服务器端会话列表
 * @type {Function}
 */
httpSession.MsgChatListRes = protocol_1.default.Response.extend({
    uri: http_constant_1.default.HTTP.URI_MSG_CHATLIST_RES,
    init: function () {
        this.uid = 0;
        this.chats = [];
        this.next = 0;
        this.rescode = 0;
        this.requestId = 0;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.chats, bufferType_1.default.ARRAY_ARRAY);
        this.push(this.next);
        this.push(this.rescode);
        this.push(this.requestId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        var byteItems = this._popArrayArray();
        for (var i = 0; i < byteItems.length; i++) {
            if (byteItems[i].byteLength > 0) {
                this.chats.push(protocol_1.default.Response.fromBuffer(byteItems[i]));
            }
        }
        this.next = this.popInt();
        this.rescode = this.popInt();
        this.requestId = this.popLong().value();
    }
});
httpSession.fromBase64ToBuffer = function (base64Str, Msg) {
    return (new Msg()).parserFromBuffer(base64_1.default.b64toBA(base64Str).buffer);
};
/**
 * 服务器端登录地址
 * @type {Function}
 */
httpSession.LvsLoginAddr = protocol_1.default.Response.extend({
    uri: http_constant_1.default.SVID_LVS << 16 | 11,
    init: function () {
        this.ip = [];
        this.port = '';
        this.domain = '';
        this.longPollingAddr = '';
    },
    getAddr: function () {
        var protocal = userData_1.default.get('useHTTPS') ? 'wss://' : 'ws://';
        if (this.domain) {
            return protocal + this.domain + ':' + this.port;
        }
        return protocal + this.ip.reverse().join('.') + ':' + this.port;
    },
    getLongPollingAddr: function () {
        return this.longPollingAddr;
    },
    unmarshall: function () {
        this.ip.push(this.popByte());
        this.ip.push(this.popByte());
        this.ip.push(this.popByte());
        this.ip.push(this.popByte());
        this.port = this.popShort();
        this.domain = this.popString();
        this.longPollingAddr = this.popString();
    }
});
exports.default = httpSession;


//# sourceURL=webpack://MTDX/./src/core/http/http.session.ts?